﻿using GetSlaughterItem.API.Application.Commands.Week03.Reports;
using GetSlaughterItem.API.Controllers.SuYi;
using MediatR;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
using SlaughterItem.Common.Dtos;

namespace GetSlaughterItem.API.Controllers
{
    /// <summary>
    /// 报表控制器
    /// </summary>
    [Route("api/[controller]/[action]")]
    [ApiController]
    public class ReportsController : ControllerBase
    {
        private readonly IMediator mediator;
        private readonly ILogger<ReportsController> logger;
        /// <summary>
        /// 构造函数
        /// </summary>
        /// <param name="mediator"></param>
        public ReportsController(IMediator mediator, ILogger<ReportsController> logger)
        {
            this.mediator = mediator;
            this.logger = logger;
        }


        /// <summary>
        /// 进场登记明细
        /// </summary>
        /// <param name="cmd"></param>
        /// <returns></returns>
        [HttpPost]
        public async Task<Result> QueryCheckDetail(Check_InDetailQueryCommand cmd)
        {
            try
            {
                logger.LogInformation("进场登记明细显示查询");
                return await mediator.Send(cmd);
            }
            catch (Exception ex)
            {
                logger.LogError("进场登记明细查询失败" + ex.Message);

                throw;
            }
        }

        /// <summary>
        /// 白条称重明细显示
        /// </summary>
        /// <param name="cmd"></param>
        /// <returns></returns>
        [HttpPost]
        public async Task<Result> QueryWhiteporkReports(WhiteporkReportsQueryCommand cmd)
        {
            try
            {
                logger.LogInformation("白条称重明细显示");
                return await mediator.Send(cmd);
            }
            catch (Exception ex)
            {
                logger.LogError("白条称重明细显示失败" + ex.Message);

                throw;
            }
        }
        /// <summary>
        /// 白条称重汇总
        /// </summary>
        /// <param name="cmd"></param>
        /// <returns></returns>
        [HttpPost]
        public async Task<Result> QueryWhiteporkCollect(WhiteporkCollectQueryCommand cmd)
        {
            try
            {
                logger.LogInformation("白条称重汇总");
                return await mediator.Send(cmd);
            }
            catch (Exception ex)
            {
                logger.LogError("白条称重汇总失败" + ex.Message);

                throw;
            }
        }
    }
}
